// 导入 axios 库
import axios from 'axios';


const request = axios.create({
    baseURL: '/ftyyptapi',
    timeout: 10000,
})


request.interceptors.request.use(
    (config) => {
        const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxNTA5MSwiaWF0IjoxNzU1MTY5Nzc3fQ.2ai7E06OhbMvSyz7vZbbnUSRfui5BrUKSvIoqeef0aA'
        if (token) {
            config.headers.token = token
        }
        return config
    },
    (err) => {
        return Promise.reject(err);
    }
);

request.interceptors.response.use(
    (res) => {
        return res.data
    },
    (err) => {
        return Promise.reject(err)
    }
)

export const get = (url = '', params = {}, options = {}) => {
    return request.get(
        encodeURI(url),
        { params, ...options }
    );
}

export const post = (url = '', data = {}, options = {}) => {
    return request.post(
        encodeURI(url),
        data,
        options
    );
}
export const put = (url = '', data = {}, options = {}) => {
    return request.put(
        encodeURI(url),
        data,
        options
    );
}
export const patch = (url = '', data = {}, options = {}) => {
    return request.patch(
        encodeURI(url),
        data,
        options
    );
}

export const del = (url = '', params = {}, options = {}) => {
    return request.delete(
        encodeURI(url),
        { params, ...options }
    );
}

